<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.jsp.pojo.Student" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: wzm
  Date: 2023/11/9
  Time: 14:28
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
	<title>Title</title>
</head>
<body>
<%--获取转发时request对象中存储的list对象然后动态显示在jsp页面上--%>
<%--<%=request.getAttribute("list")%>--%>
<%

	String name = "张三";
    request.setAttribute("name",name);
    Student student1 = new Student(1,"张三",20,"男","北京",1);
    request.setAttribute("stu",student1);

	Map<String,Object> map = new HashMap<>();
    map.put("key1","value1");
    map.put("key2","value2");
	request.setAttribute("map",map);

%>
<%--获取单个值--%>
${name}
<hr>
<%--获取对象的属性值--%>
${stu}
<hr>
输出stu对象的name:${stu.name} <br>
输出stu对象的age:${stu.age} <br>
输出stu对象的address:${stu.address}
<hr>
<%--el表达式取值--%>
<%--获取整个集合--%>
${list}
<hr>
<%--获取集合中某个对象--%>
${list[2]}
<hr>
${list[2].name}
<hr>
<%--获取map集合--%>
${map}
<hr>
<%--获取map中某个key值--%>
${map.key2}
<hr>
<%--el表达式可以运算--%>
${5 == 5} 或者 ${5 eq 5}
${5 != 5} 或者 ${5 ne 5}
${5 > 5}  或者 ${5 gt 5}
${5 <5}  或者 ${5 lt 5}
${5 >= 5}  或者 ${5 ge 5}
${5 <= 5}    或者 ${5 le 5}

${12 == 12 && 12 < 11}
${12 == 12 || 12 < 11}
<%--${!12 == 12}--%>
<hr> 1111
${12 == 12}
${12 + 8}
${12 - 8}
${12 / 8}  ${12 div 8}
${12 % 8} ${12 mod 8}

<%--可以判断值的空--%>
${empty list}
${empty name}
${empty student}

${12 != 12 ? "确实是":"不对吧"}
<%--获取系统信息--%>
${pageContext.request.method}
${pageContext.request.serverPort}
${pageContext.request.serverName}


<div>&lt;&lt;p&gt;&gt;</div>

<hr>

<table border="1px" cellspacing="0" width="80%" align="center" style="text-align: center;">
	<tr>
		<td>编号</td>
		<td>名字</td>
		<td>年龄</td>
		<td>性别</td>
		<td>住址</td>
		<td>状态</td>
		<td>操作</td>
	</tr>
	<%--需要遍历 list--%>
	<%
		List<Student> list = (List<Student>) request.getSession().getAttribute("list");
		for (int i = 0; i < list.size(); i++) {
            //每次遍历取出一个学生
			Student student = list.get(i);
	%>
	<tr>
		<td><%=student.getId()%></td>
		<td><%=student.getName()%></td>
		<td><%=student.getAge()%></td>
		<td><%=student.getSex()%></td>
		<td><%=student.getAddress()%></td>
		<td><%=student.getStatus() == 1 ? "启用" : "禁用"%></td>
		<td>
			<a href="#">删除</a>
			<a href="#">修改</a>
		</td>

	</tr>
	<%
		}
	%>


</table>
<hr>
<h1>EL+JSTL</h1>

<table border="1px" cellspacing="0" width="80%" align="center" style="text-align: center;">
	<tr>
		<td>编号</td>
		<td>名字</td>
		<td>年龄</td>
		<td>性别</td>
		<td>住址</td>
		<td>状态</td>
		<td>操作</td>
	</tr>
	<%--需要遍历 list--%>

	<c:forEach items="${list}" var="student">
	<tr>
		<td>${student.id}</td>
		<td>${student.name}</td>
		<td>${student.age}</td>
		<td>${student.sex}</td>
		<td>${student.address}</td>
		<td>${student.status == 1 ? "启用" : "禁用"}</td>
		<td>
			<a href="/web07/student/delete?id=${student.id}">删除</a>
			<a href="#">修改</a>
		</td>
	</tr>
	</c:forEach>


</table>
</body>
</html>
